package cn.tedu.egmvc5.controller;

import cn.tedu.egmvc5.mapper.AddressMapper;
import cn.tedu.egmvc5.pojo.dto.AddressAddParam;
import cn.tedu.egmvc5.pojo.entity.Address;
import cn.tedu.egmvc5.pojo.vo.AddressInfoVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/v1/address/")
public class AddressController {
    @Autowired
    private AddressMapper addressMapper;

    @PostMapping("add")
    public String addAddress(AddressAddParam addressAddParam){
        addressMapper.insertAddress(addressAddParam);
        return "添加成功";
    }

    @GetMapping("list")
    public List<AddressInfoVO> listAddress(){
        return addressMapper.selectAddress();
    }

    @PostMapping("del")
    public String delAddress(Integer id){
        addressMapper.deleteAddress(id);
        return "删除成功";
    }
}
